/**
 * @description: 全员营销活动列表页
 *
 * @author Yangcl
 * @date 2018年6月22日 上午10:35:27
 * @version 1.0.0.1
 */
var aemJoinList = {
		
		myDataTable : null,  
		aemInfoId : null ,
		// 搜索条件
		startTime : "",
		endTime : "",
		description : "",
		openId : "",
		
		init:function(aemInfoId_){ 
			aemJoinList.aemInfoId = aemInfoId_;
			return aemJoinList;  
		},
		
		dataTable : function(){
			aemJoinList.myDataTable = $('#page-list-table').DataTable({
				columns: [
	         		{"data":"nickName"},		// 微信昵称
	         		{"data":"openId"},	// OpenID
	         		{"data":"staffId"},   // 用户身份
	         		{"data":"createTimeString"}, // 奖励时间
	         		{"data":"description"},   // 奖励原因
	         		{"data":"clickNickName"}, 	 // 来源昵称
	         		{"data":"clickOpenId"}, 	 // 来源OpenId
	         		{"data":"score"} 	 // 奖励内容
	         	],
	         	
	         	ajax:{
	     	    	contentType: 'application/json;charset=utf-8',
	     	    	type: 'POST',
	     	    	url: aemJoinList.getPath() + "/aemInfo/ajaxAemJoinPageList",
	     	    	data: function(e){
	     	    		e.aemInfoId = aemJoinList.aemInfoId;
	     	    		e.startTime = aemJoinList.startTime; 
	     	    		e.endTime = aemJoinList.endTime;
	     	    		e.description = aemJoinList.description;
	     	    		e.openId = aemJoinList.openId;
	     	    		e.scoreType = aemJoinList.scoreType;
	     				return JSON.stringify(e); 
	     			}
	     		},
	         	
	     		processing: true,
	     		ordering: false,
	     		searching: false,
	     		info: true,
	     		autoWidth: true,
	     		lengthChange: false,
	     		"order": [[ 2, "desc" ]],
	     	    language: {
	     	    	emptyTable: '没有数据',
	     	    	info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
	     			infoEmpty: '没有数据',
	     			lengthMenu: '每页显示 _MENU_ 条记录',
	     			loadingRecords: '正在加载数据....',
	     			processing: '正在处理数据....',
	     			zeroRecords: '没有找到匹配的记录',
	     			paginate: {
	     				first: '首页',
	     				previous: '前页',
	     				next: '后页',
	     				last: '尾页'
	     			}
	     	    },
	     	    order: [[1,'desc']],
	     		pageLength: 10,
	     	    pagingType: 'full_numbers',
	     	    columnDefs: [
	     	    	{
		     			render: function(data, type, e) { 
		     				var  result = '';
		     				if(e.staffId != null){
		     					result = '员工';
		     				}
		     				/*if(typeof(e.memberId) == "undefined"){
		     					result = '会员';
		     				}*/
		     				return result;
		                 },
		     			targets: 2
	     	    	},
	     	    	{
		     			render: function(data, type, e) { 
		     				if(e.clickNickName == 'null' || e.clickNickName == null || typeof(e.clickNickName) == 'undefined'){
		     					return '暂无';
		     				} 
		     				return e.clickNickName;
		                 },
		     			targets: 5
	     	    	}
     	    	],
	     	    serverSide: true,
	     	    "initComplete": function(settings, json) { 
	     	    }
	     	});
			
			return aemJoinList.myDataTable; 
		},
		
		// 搜索
		search : function(){
			aemJoinList.startTime = $("#start-time").val(); 
			aemJoinList.endTime = $("#end-time").val(); 
			aemJoinList.scoreType = $("#score-type").val(); 
			aemJoinList.openId = $("#open-id").val();
			aemJoinList.myDataTable.ajax.reload(function(){});
		},
		
		// 导出CSV
		exportAemJoinList : function(){
			window.location.href = aemJoinList.getPath() + "/aemInfo/ajaxExportAemJoinList?id=" + aemJoinList.aemInfoId ;
		},
		
		getPath : function(){ 
			return window.parent.servicePath;
		},
		
		trim : function(str) {
		    return str.replace(/(^\s+$)/g, "");
		},
		
		/**
		 * 发送ajax请求                                
		 * 
		 * type_ : post or get
		 * url_ : url 
		 * data_ : data_
		 * async_ : sync type ,true or false
		 */
		syncAjax : function(type_, url_, data_  , async_) {
			var msg_ = null;
			$.ajax({
					dataType : "text",
					type : type_,
					url : url_,
					data : data_,
					async : async_, 
					success : function(msg) {
							msg_ = msg;
					},
					error : function(msg) {
							msg_ = msg;
					}
			});
			return msg_;
		},
		
		parseUrl : function(url) {
	        var a =  document.createElement('a');
	        a.href = url;
	        return {
	            source: url,
	            protocol: a.protocol.replace(':',''),
	            host: a.hostname,
	            port: a.port,
	            query: a.search,
	            params: (function(){
	                var ret = {},
	                    seg = a.search.replace(/^\?/,'').split('&'),
	                    len = seg.length, i = 0, s;
	                for (;i<len;i++) {
	                    if (!seg[i]) { continue; }
	                    s = seg[i].split('=');
	                    ret[s[0]] = s[1];
	                }
	                return ret;
	            })(),
	            file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
	            hash: a.hash.replace('#',''),
	            path: a.pathname.replace(/^([^\/])/,'/$1'),
	            relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
	            segments: a.pathname.replace(/^\//,'').split('/')
	        };
	    }
}




















